package com.xiaolin.oa.controller;

import com.github.pagehelper.PageInfo;
import com.xiaolin.oa.annotations.HasApi;
import com.xiaolin.oa.model.entity.CommonProcessNode;
import com.xiaolin.oa.service.CommonProcessNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolin
 * @description 描述
 * @since 2024/7/12
 */
@Api("审批流程节点资源")
@RestController
@RequestMapping("/processNode")
public class CommonProcessNodeController {

    @Autowired
    private CommonProcessNodeService processNodeService;

    @HasApi({"processNode:home"})
    @ApiOperation("获取审批流程节点列表")
    @PostMapping("/getPage/{page}/{pageSize}")
    public PageInfo<CommonProcessNode> getProcessNodePage(@PathVariable Integer page,
                                             @PathVariable Integer pageSize,
                                             @RequestBody CommonProcessNode processNode) {
        return processNodeService.getProcessNodePage(page, pageSize, processNode);
    }

    @HasApi({"processNode:add"})
    @ApiOperation("添加审批流程节点")
    @PostMapping("/add")
    public boolean addProcessNode(@RequestBody CommonProcessNode processNode) {
        return processNodeService.addProcessNode(processNode);
    }

    @HasApi({"processNode:get"})
    @ApiOperation("获取审批流程节点")
    @PostMapping("/get/{id}")
    public CommonProcessNode getProcessNode(@PathVariable("id") Integer id) {
        return processNodeService.getProcessNode(id);
    }

    @HasApi({"processNode:update"})
    @ApiOperation("修改审批流程节点")
    @PostMapping("/update")
    public boolean updateProcessNode(@RequestBody CommonProcessNode processNode) {
        return processNodeService.updateProcessNode(processNode);
    }

    @HasApi({"processNode:del"})
    @ApiOperation("删除审批流程节点")
    @PostMapping("/delete/{id}")
    public boolean deleteProcessNode(@PathVariable Integer id) {
        return processNodeService.deleteProcessNode(id);
    }

    @HasApi({"processNode:binding:user"})
    @ApiOperation("流程节点绑定审批人")
    @PostMapping("/configProcessNodeForUsers/{processNodeId}/{optType}")
    public boolean configProcessNodeForUsers(@PathVariable Integer processNodeId,
                                      @PathVariable String optType,
                                      @RequestBody List<Integer> userIds) {
        return processNodeService.configProcessNodeForUsers(processNodeId, optType, userIds);
    }

    @HasApi({"processNode:bound:users"})
    @ApiOperation("流程节点绑定审批人")
    @PostMapping("/getBoundUsers/{processNodeId}")
    public List<Integer> getBoundUsers(@PathVariable Integer processNodeId) {
        return processNodeService.getBoundUsers(processNodeId);
    }
}
